package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.dao.RefundInvoiceDao;
import com.xbongbong.saas.domain.entity.RefundInvoiceEntity;
import com.xbongbong.saas.model.RefundInvoiceModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/3/25 20:14
 * @since v1.0
 */
@Service("refundInvoiceModel")
public class RefundInvoiceModelImpl implements RefundInvoiceModel {

    @Resource
    private RefundInvoiceDao refundInvoiceDao;
    /**
     * 数据单条查询
     *
     * @param key    主键ID
     * @param corpid 公司ID
     * @return Integer
     * @author feng.zheng
     * @date 2019/2/15 20:27
     * @since v1.0
     */
    @Override
    public RefundInvoiceEntity getByKey(Long key, String corpid) {
        return refundInvoiceDao.getByKey(key, corpid);
    }

    /**
     * 保存
     *
     * @param refundInvoiceEntity 实体
     * @return Integer
     * @throws XbbException
     * @author Jian.Wang
     * @date 2019/1/23 20:27
     * @since v1.0
     */
    @Override
    public Integer save(RefundInvoiceEntity refundInvoiceEntity) throws XbbException {
        if (refundInvoiceEntity.getId() == null || refundInvoiceEntity.getId() == 0) {
            return insert(refundInvoiceEntity);
        } else {
            return update(refundInvoiceEntity);
        }

    }

    /**
     * 根据id删除
     *
     * @param key    主键
     * @param corpid 公司id
     * @return 是否成功
     */
    @Override
    public Integer deleteByKey(Long key, String corpid) {
        return refundInvoiceDao.deleteByKey(key, corpid);
    }

    /**
     * 插入
     *
     * @param entity 实体
     * @return 是否成功
     * @throws XbbException 数据库操作异常
     */
    @Override
    public Integer insert(RefundInvoiceEntity entity) throws XbbException {
        return refundInvoiceDao.insert(entity);
    }

    /**
     * 更新
     *
     * @param entity 实体
     * @return 是否成功
     * @throws XbbException 数据库操作异常
     */
    @Override
    public Integer update(RefundInvoiceEntity entity) throws XbbException {
        return refundInvoiceDao.update(entity);
    }

    /**
     * 根据参数查询
     *
     * @param param 查询条件
     * @return 实体集合
     */
    @Override
    public List<RefundInvoiceEntity> findEntitys(Map<String, Object> param) {
        return refundInvoiceDao.findEntitys(param);
    }

    /**
     * 获取符合查询条件的记录总数
     *
     * @param param 查询条件
     * @return 符合查询条件的记录总数
     */
    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return refundInvoiceDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    /**
     * 获取发票id
     *
     * @param param 参数
     * @return 删除成功
     * @author haibin.zhang
     * @since 3.12
     * 添加时间 2017/9/5
     */
    @Override
    public List<Long> getInvoiceId(Map<String, Object> param) {
        return refundInvoiceDao.getInvoiceId(param);
    }

    /**
     * 根据红冲合同id删除
     *
     * @param contractId 红冲合同id
     * @param corpid     公司id
     * @return 删除成功
     * @author haibin.zhang
     * @since 3.12
     * 添加时间 2017/9/5
     */
    @Override
    public Integer deleteByContractId(Long contractId, String corpid) {
        return refundInvoiceDao.deleteByContractId(contractId, corpid);
    }

    /**
     * 根据退货退款list删除
     *
     * @param corpid       公司id
     * @param refundIdList 退货退款id
     * @return 删除成功
     * @author youli.chen
     * @since 3.12
     * 添加时间 2017/9/5
     */
    @Override
    public Integer deleteBatchByRefundIdIn(String corpid, List<Long> refundIdList) {
        return refundInvoiceDao.deleteBatchByRefundIdIn(corpid, refundIdList);
    }

    /**
     * 根据退货退款list回滚数据
     *
     * @param corpid       公司id
     * @param refundIdList 退货退款id
     * @return 回滚成功
     * @author youli.chen
     * @since 3.12
     * 添加时间 2017/9/5
     */
    @Override
    public Integer updateRollbackByRefundId(String corpid, List<Long> refundIdList) {
        return refundInvoiceDao.updateRollbackByRefundId(corpid, refundIdList);
    }

    /**
     * 根据发票id删除
     *
     * @param invoiceId 发票id
     * @param corpid    公司id
     * @return 删除成功
     * @author haibin.zhang
     * @since 3.12
     * 添加时间 2017/9/5
     */
    @Override
    public Integer deleteByInvoiceId(Long invoiceId, String corpid) {
        return refundInvoiceDao.deleteByInvoiceId(invoiceId, corpid);
    }
}
